/*
 * Copyright (C) 2010-2012 Susanta Tewari
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package genomemap.nb.jobs.properties.editors;

import java.beans.PropertyEditorSupport;
import java.util.ArrayList;
import java.util.List;

/**
 * Value type is String.
 *
 * @author Susanta Tewari
 * @history Created on Aug 26, 2012.
 */
public class TAB08LHoodAlgorithmsPE extends PropertyEditorSupport {

    /**
     * Enum description
     *
     */
    public enum TAB08LHoodAlgorithm {

        STRAIGHTFORWARD {

            /**
             * Method description
             *
             *
             * @return
             */
            @Override
            public String implCode() {
                return TAB08_SFA;
            }
        },
        RECURSIVE_LINKING {

            /**
             * Method description
             *
             *
             * @return
             */
            @Override
            public String implCode() {
                return TAB08_RLA;
            }
        };

        /** Field description */
        private static final String TAB08_SFA = "tab08:sfa";

        /** Field description */
        private static final String TAB08_RLA = "tab08:rla";

        /**
         * Method description
         *
         *
         * @return
         */
        public String implCode() {
            throw new RuntimeException("must be overridden");
        }

        /**
         * Method description
         *
         *
         * @param implCode
         *
         * @return
         */
        public static TAB08LHoodAlgorithm valueOfImplCode(final String implCode) {

            switch (implCode) {

                case TAB08_SFA :
                    return STRAIGHTFORWARD;

                case TAB08_RLA :
                    return RECURSIVE_LINKING;

                default :
                    return null;
            }
        }
    }

    /**
     * Method description
     *
     *
     * @return
     */
    @Override
    public String[] getTags() {

        final List<String> list = new ArrayList<>(2);

        for (final TAB08LHoodAlgorithm algo : TAB08LHoodAlgorithm.values()) {
            list.add(algo.name());
        }

        return list.toArray(new String[0]);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    @Override
    public String getAsText() {

        final String implCode          = (String) getValue();
        final TAB08LHoodAlgorithm algo = TAB08LHoodAlgorithm.valueOfImplCode(implCode);

        if (algo == null) {
            return "No Value";
        }

        return algo.name();
    }

    /**
     * Method description
     *
     *
     * @param s
     *
     * @throws IllegalArgumentException
     */
    @Override
    public void setAsText(final String s) throws IllegalArgumentException {

        final TAB08LHoodAlgorithm algo = TAB08LHoodAlgorithm.valueOf(s);

        if (algo == null) {
            throw new IllegalArgumentException("Invalid value");
        }

        setValue(algo.implCode());
    }
}
